<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
    <head>
        <title></title>
        <meta charset="utf-8">
        <meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
        <link rel="stylesheet" href="css/ui-base.css">
        <link rel="stylesheet" href="css/ui-box.css">
        <link rel="stylesheet" href="css/ui-color.css">
        <link rel="stylesheet" href="css/appcan.icon.css">
        <link rel="stylesheet" href="css/appcan.control.css">
        <link rel="stylesheet" href="seller_info_content/css/main.css">
        <link rel="stylesheet" href="css/fonts/font-awesome.min.css">
    </head>
    <body class="um-vp bc-bg" ontouchstart>
        <div class="ub ub-ac uinn-de1">
            <div class="umh-list8 umw-list6"> <img src="" id="bookimg" height="300em" width="200em"> </div>
            <div class="ub ub-ver uinn">
                <div class="ulev-app2 t-bla " id="bookName">
                </div>
                <div class="ulev-4 t-gra-book uinn-details" id="bookSeller">
                </div>
                <div class="ulev-4 t-gra-book uinn-details" id="bookOldPrice">
                </div>
                <div class="ulev-4 t-gra-book uinn-details" id="bookNewPrice">
                </div>
                <div class="btn ub ub-ac bc-text-head ub-pc bc-btn"  id="buybook">
                	买买买
                </div>

            </div>
        </div>
        <div id="listview" class="umar-a sc-bg">
        </div>

    </body>
    <script src="js/appcan.js"></script>
    <script src="js/appcan.control.js"></script>
    <script src="js/appcan.listview.js"></script>
    </body>
    <script>
        var flag = 0;
        var arrData = [];
        var seller_name = localStorage.getItem('seller_name');
        var seller_price = localStorage.getItem('seller_price');
        var goods_id = localStorage.getItem('goods_id');
        
        var username = localStorage.getItem("username");
        appcan.ready(function() {
            appcan.initBounce();
            showGoodInfo();
            //alert(goods_id);
if (seller_name == null) seller_name = "zengxinlu";  // for debug
if (username == null) username = "1";  // for debug
            var request = appcan.require('request');
            request.ajax({
                type : 'POST',
                url : 'http://whynothappy.sinaapp.com/books_of_a_seller',
                data : {username : username, seller : seller_name},
                contentType: 'application/json',
                success:function(data){
                    //alert(data);
                    data = eval("(" + data + ")");
                    show(data.books, 0);
                },
                error:function(){
                    alert("can't connect the Internet");
                }
            })
        })
        function showGoodInfo() {
            //alert(localStorage.getItem('book_img'));
            $('#bookimg')[0].src = localStorage.getItem('book_img');
            $('#bookName')[0].innerHTML = localStorage.getItem('book_name');
            $('#bookSeller')[0].innerHTML = "卖家： " + seller_name;
            $('#bookNewPrice')[0].innerHTML = "现价：￥" + localStorage.getItem('seller_price');
            $('#bookOldPrice')[0].innerHTML = "原价：￥" + localStorage.getItem('book_price');
        }
        function show(data, index) {
            var len = data.length;
            for(var i = 0; i < len; ++i)
            {
                var request = appcan.require('request');
                request.ajax({
                    type : 'POST',
                    url : 'http://whynothappy.sinaapp.com/goodsinfo',
                    data : {goods_id : data[i].goods_id},
                    contentType: 'application/json',
                    success:function(data){
                        //alert(data);
                        data = eval("(" + data + ")");
                        AddGoods(data, index);
                        //alert("can't connect the Internet");
                    },
                    error:function(){
                        alert("can't connect the Internet");
                    }
                })
            }
            
        }
        function down(x, y) {
            return (x.price > y.price) ? 1 : -1
 
        }
        function AddGoods(data, index) {
            arrData.push({
                "bookname":data.title, 
                "img":data.pic_url, 
                "price": data.price
            });
            arrData.sort(down);
            var listData = [];
            for (var i = 0,
                len = arrData.length; i < len; i++) {
                    
                var list = {
                    title : arrData[i].bookname,
                    icon : arrData[i].img,
                    price :  arrData[i].price,
                    img : arrData[i].img,
                    describe : '<div class="ub ub-ae"><div class="sc-text-warn ">' + arrData[i].price + '</div></div>',
                }
                listData.push(list);
            }
            var lv1 = appcan.listview({
                selector : "#listview",
                type : "thickLine",
                hasIcon : true,
                hasAngle : true,
                hasSubTitle : false,
                multiLine : 1,
                hasCheckbox : false,
                align : 'left'
            });
            lv1.set(listData);
            lv1.on('click', function(ele, context, obj, subobj) {
                //alert(context.title);
                //alert(obj[0].id)
                localStorage.setItem('book_name',context.title);
                localStorage.setItem('seller_price',context.price);
                localStorage.setItem('book_img',context.img);
                showGoodInfo();
            })
        }
        appcan.button("#buybook", "ani-act", function() {
            appcan.alert("提示", "确定购买书籍？", ["确定", "取消"], send);
        })
        function send(e,idx){
            if (idx == 1) return;
            var request = appcan.require('request');
            request.ajax({
                type : 'POST',
                url : 'http://whynothappy.sinaapp.com/buy',
                data : {username : username , goods_id : goods_id},
                contentType: 'application/json',
                success:function(data){
                    data = eval("(" + data + ")");
                    alert("购买成功");
                },
                error:function(){
                    alert("can't connect the Internet");
                }
            })
        }
 </script>
</html>
